package com.alpha.service.config;

import com.alpha.service.context.AlphaApplicationContext;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * open api 接口文档配置
 *
 * @author chenruwan
 * @since 2022-01-01
 */
@Configuration
public class OpenApiConfiguration {
    @Bean
    public OpenAPI openApi() {
        return new OpenAPI().info(new Info()
                .title(AlphaApplicationContext.getApplicationName() + " API Doc")
                .description("接口文档")
                .version("1.0.0"));
    }

    @Bean
    @ConditionalOnClass({WebMvcConfigurer.class})
    public GroupedOpenApi groupedOpenApi() {
        return GroupedOpenApi.builder()
                .group(AlphaApplicationContext.getApplicationName())
                .pathsToMatch("/**")
                .build();
    }
}
